import env from 'constants/env.json'
import {AppContainer} from 'modules'
import {PosModule} from 'native-modules'
import React, {useEffect} from 'react'
import {useScreens} from 'react-native-screens'
import AppProvider from 'services/AppProvider'
import {setPosInfo, setVersion} from 'services/authorization'
import {navigator} from 'services/navigation'
import {AppState, Alert} from 'react-native'
import {rejects} from 'assert'
import {Toast} from 'components'
import {PayProvide} from 'services/PayContext'

useScreens()
const App: React.FC = () => {
  useEffect(() => {
    try {
      PosModule.setId(env.ums.appId).then((res: boolean) => {})
      PosModule.setAppKey(env.ums.appKey).then((res: boolean) => {})
    } catch (ex) {}
    try {
      setPosInfo()
    } catch (ex) {}
    //自更新
    try {
      if (env.ums.appKey) {
        PosModule.autoSelfUpdate()
          .then(res => {
            Toast.show(res)
          })
          .catch(er => {
            Toast.show(JSON.stringify(er))
          })
      }
    } catch (ex) {
      Toast.show(JSON.stringify(ex))
    }
    try {
      setVersion(env.version)
      PosModule.setupCardReader({
        loginAddress: 'http://service.unimarspay.com:20080/decsrv/login',
        md5Key: 'C11F438513BCE992C8FD38745B8AAAC4',
      })
    } catch (ex) {}
  }, [])

  return (
    <AppProvider providers={[PayProvide]}>
      {/* <TouchableHighlight
			style={{ width: '100%', height: '100%' }}
			onPress={() => {
				operate()
			}}>
			
		</TouchableHighlight> */}
      <AppContainer ref={navigator} />
    </AppProvider>
  )
}

export default App
